<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字</title>
</head>
<body>
    <div>请输入要猜的数字</div>
    <input type="text">
    <button type="submit">提交</button>
    <span id="n"></span>
    <span id="m"></span>
</body>
<script>
    //生成一个随机数
    let random = parseInt(100 * Math.random()) + 1;
    //获取猜数字操作节点
    let input = document.querySelector('input');
    let btn = document.querySelector('button');
    let span = document.querySelector('#m')
    let s = document.querySelector('#n');
    let sum = 0
    btn.onclick = () =>{
        if(input.value == ''){
            alert('不能为空')
            return
        };
        let num = input.value;
        if(num < random){
            span.innerHTML = '猜小了';
            sum++;
            s.innerHTML = `提交次数：${sum}`;
        }else if(num > random){
            span.innerHTML = '猜大了';
            sum++;
            s.innerHTML = `提交次数：${sum}`;
        }else{
            span.innerHTML = '猜对了';
        }
    }
</script>
</html>